package com.zhang.learn.netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.junit.Test;

/**
 * @author zhanghaolian
 * @date 2022/2/28 10:47
 */
public class NettyLearn {
    @Test
    public void test() {
        //构造两个线程组
        EventLoopGroup boss = new NioEventLoopGroup();
        EventLoopGroup worker = new NioEventLoopGroup();

        try {
            ServerBootstrap server = new ServerBootstrap()
                    .group(worker, worker)
                    .channel(NioServerSocketChannel.class)
                    .handler(new HttpServerInitializer());

            ChannelFuture future = server.bind(8080).sync();
            //等待服务端口关闭
            future.channel().closeFuture().sync();
        }catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            // 释放线程池资源
            boss.shutdownGracefully();
            worker.shutdownGracefully();
        }
    }


}
